package org.example.view;

import org.example.entity.Admin;
import org.example.service.*;

import java.io.IOException;
import java.security.SecureRandom;
import java.util.Scanner;

/**
 * @author TonySong
 * @date 2025/7/28 0028
 * @time 16:42
 */
public class View {
    private static final Scanner in =new Scanner(System.in,"utf-8");

    public static Admin login(){
        //思考：该方法的返回值为什么是Admin对象？可以是其它值吗？为什么
       IAdminService adminService =new AdminService();
        System.out.println("请输入账号：");
        String username=in.next();
        System.out.println("请输入密码：");
        String password=in.next();
        return adminService.login(username, password);
    }
    public static void main(String[] args) throws IOException {
        Admin login = login();
        ICinemaService cinemaService = new CinemaService();
        IBuyTicketService buyTicketService = new BuyTicketService();
        if(login!=null) {
            System.out.println("登录成功！");
            int m =0;
            do {

                System.out.println("1: 浏览电影 2：购买  3：查询购物车  4：继续购票  5：读取历史记录  6：退出");
                m = in.nextInt();
                switch (m) {
                    case 1:
                        cinemaService.showMovies();
                        break;
                    case 2:
                        System.out.println("请输入电影名称：");
                        String name = in.next();
                        System.out.println("请输入播放时间：");
                        String playTime = in.next();
                        System.out.println("请选择票的类型：1.普通票 2.学生票 3.免费票");
                        int type = in.nextInt();
                        buyTicketService.buyTicket(name, playTime, type);
                        break;
                    case 5:
                        TicketService.printTickets();

                }
            } while (m!=6);
        }else{
            System.out.println("对不起，账号或密码错误！");
        }
    }
}
